<template>
	<view class="container">
		<view class="" style="display: flex;align-items: center;margin-top: 0px;">
			<view class="tag">标题：</view>
			<uni-easyinput v-model="user.title" placeholder="请输入标题" />
		</view>
		<view class="" style="display: flex;align-items: center;margin-top: 20px;">
			<view class="tag">内容：</view>
			<uni-easyinput v-model="user.content" type="textarea" placeholder="请输入内容" />
		</view>
		<uni-file-picker @delete="cancel" style="margin-top: 10px;" @select="select" title="请选择图片" limit="9"
			file-mediatype="image"></uni-file-picker>
		<button type="primary" @click="submit" style="margin-top: 20px;">提交</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: {
					title: "",
					content: "",
					name: "",
					time: "",
					like: 0,
					image: []
				}
			};
		},
		onLoad(item) {

		},
		onReady() {

		},
		onShow() {

		},
		methods: {
			cancel(e) {
				this.user.image.splice(this.user.image.findIndex(t => {
					return t == e.tempFile.path
				}), 1)
			},
			select(e) {
				console.log(e);
				this.user.image = e.tempFilePaths
			},
			submit() {
				if (this.user.image.length == 0) {
					uni.showToast({
						title: '请选择图片',
						icon: 'none'
					});
					return
				}
				this.user.name = uni.getStorageSync("user").nickName
				this.user.time = new Date()
				this.isEmpty(this.user)
				this.$request.t3.unshift(JSON.parse(JSON.stringify(this.user)))
				uni.showToast({
					title: '发表成功',
					icon: 'none'
				});
				setTimeout(function() {
					uni.navigateBack({
						delta: 1
					});
				}, 300);
			}
		}
	};
</script>

<style lang="scss">
	page {
		background-color: white;
	}
</style>
